const { exec } = require('../db')
const jwt=require('jsonwebtoken')

const router = require('koa-router')()

router.post('/login', async (ctx, next) => {
    let {username,password}=ctx.request.body
    let sql=`SELECT * FROM userlist WHERE username='${username}' AND password='${password}'`
    const data=await exec(sql)
    if(data.length>0){
        ctx.body={
            code:200,
            mes:'登录成功',
            token:jwt.sign({username},'1906A')
        }
    }else{
        ctx.body={
            code:401,
            mes:'登录失败'
        }
    }
})


module.exports = router
